#
#   mpr-freebsd-default.mk -- Makefile to build Embedthis MPR for freebsd
#

NAME                  := mpr
VERSION               := 6.2.1
PROFILE               ?= default
ARCH                  ?= $(shell uname -m | sed 's/i.86/x86/;s/x86_64/x64/;s/arm.*/arm/;s/mips.*/mips/')
CC_ARCH               ?= $(shell echo $(ARCH) | sed 's/x86/i686/;s/x64/x86_64/')
OS                    ?= freebsd
CC                    ?= gcc
CONFIG                ?= $(OS)-$(ARCH)-$(PROFILE)
BUILD                 ?= build/$(CONFIG)
LBIN                  ?= $(BUILD)/bin
PATH                  := $(LBIN):$(PATH)

ME_COM_COMPILER       ?= 1
ME_COM_LIB            ?= 1
ME_COM_MATRIXSSL      ?= 0
ME_COM_MBEDTLS        ?= 1
ME_COM_NANOSSL        ?= 0
ME_COM_OPENSSL        ?= 0
ME_COM_OSDEP          ?= 1
ME_COM_SSL            ?= 1
ME_COM_VXWORKS        ?= 0

ME_COM_OPENSSL_PATH   ?= "/usr/lib"

ifeq ($(ME_COM_LIB),1)
    ME_COM_COMPILER := 1
endif
ifeq ($(ME_COM_MBEDTLS),1)
    ME_COM_SSL := 1
endif
ifeq ($(ME_COM_OPENSSL),1)
    ME_COM_SSL := 1
endif

CFLAGS                += -fPIC -w
DFLAGS                += -DME_DEBUG=0 -D_REENTRANT -DPIC $(patsubst %,-D%,$(filter ME_%,$(MAKEFLAGS))) -DME_COM_COMPILER=$(ME_COM_COMPILER) -DME_COM_LIB=$(ME_COM_LIB) -DME_COM_MATRIXSSL=$(ME_COM_MATRIXSSL) -DME_COM_MBEDTLS=$(ME_COM_MBEDTLS) -DME_COM_NANOSSL=$(ME_COM_NANOSSL) -DME_COM_OPENSSL=$(ME_COM_OPENSSL) -DME_COM_OSDEP=$(ME_COM_OSDEP) -DME_COM_SSL=$(ME_COM_SSL) -DME_COM_VXWORKS=$(ME_COM_VXWORKS) 
IFLAGS                += "-I$(BUILD)/inc"
LDFLAGS               += 
LIBPATHS              += -L$(BUILD)/bin
LIBS                  += -ldl -lpthread -lm

DEBUG                 ?= debug
CFLAGS-debug          ?= -g
DFLAGS-debug          ?= -DME_DEBUG
LDFLAGS-debug         ?= -g
DFLAGS-release        ?= 
CFLAGS-release        ?= -O2
LDFLAGS-release       ?= 
CFLAGS                += $(CFLAGS-$(DEBUG))
DFLAGS                += $(DFLAGS-$(DEBUG))
LDFLAGS               += $(LDFLAGS-$(DEBUG))

ME_ROOT_PREFIX        ?= 
ME_BASE_PREFIX        ?= $(ME_ROOT_PREFIX)/usr/local
ME_DATA_PREFIX        ?= $(ME_ROOT_PREFIX)/
ME_STATE_PREFIX       ?= $(ME_ROOT_PREFIX)/var
ME_APP_PREFIX         ?= $(ME_BASE_PREFIX)/lib/$(NAME)
ME_VAPP_PREFIX        ?= $(ME_APP_PREFIX)/$(VERSION)
ME_BIN_PREFIX         ?= $(ME_ROOT_PREFIX)/usr/local/bin
ME_INC_PREFIX         ?= $(ME_ROOT_PREFIX)/usr/local/include
ME_LIB_PREFIX         ?= $(ME_ROOT_PREFIX)/usr/local/lib
ME_MAN_PREFIX         ?= $(ME_ROOT_PREFIX)/usr/local/share/man
ME_SBIN_PREFIX        ?= $(ME_ROOT_PREFIX)/usr/local/sbin
ME_ETC_PREFIX         ?= $(ME_ROOT_PREFIX)/etc/$(NAME)
ME_WEB_PREFIX         ?= $(ME_ROOT_PREFIX)/var/www/$(NAME)
ME_LOG_PREFIX         ?= $(ME_ROOT_PREFIX)/var/log/$(NAME)
ME_SPOOL_PREFIX       ?= $(ME_ROOT_PREFIX)/var/spool/$(NAME)
ME_CACHE_PREFIX       ?= $(ME_ROOT_PREFIX)/var/spool/$(NAME)/cache
ME_SRC_PREFIX         ?= $(ME_ROOT_PREFIX)$(NAME)-$(VERSION)


TARGETS               += $(BUILD)/.install-certs-modified
ifeq ($(ME_COM_MBEDTLS),1)
    TARGETS           += $(BUILD)/bin/libmbedtls.a
endif
TARGETS               += $(BUILD)/bin/libmpr.so

unexport CDPATH

ifndef SHOW
.SILENT:
endif

all build compile: prep $(TARGETS)

.PHONY: prep

prep:
	@echo "      [Info] Use "make SHOW=1" to trace executed commands."
	@if [ "$(CONFIG)" = "" ] ; then echo WARNING: CONFIG not set ; exit 255 ; fi
	@if [ "$(ME_APP_PREFIX)" = "" ] ; then echo WARNING: ME_APP_PREFIX not set ; exit 255 ; fi
	@[ ! -x $(BUILD)/bin ] && mkdir -p $(BUILD)/bin; true
	@[ ! -x $(BUILD)/inc ] && mkdir -p $(BUILD)/inc; true
	@[ ! -x $(BUILD)/obj ] && mkdir -p $(BUILD)/obj; true
	@[ ! -f $(BUILD)/inc/me.h ] && cp projects/mpr-freebsd-default-me.h $(BUILD)/inc/me.h ; true
	@if ! diff $(BUILD)/inc/me.h projects/mpr-freebsd-default-me.h >/dev/null ; then\
		cp projects/mpr-freebsd-default-me.h $(BUILD)/inc/me.h  ; \
	fi; true
	@if [ -f "$(BUILD)/.makeflags" ] ; then \
		if [ "$(MAKEFLAGS)" != "`cat $(BUILD)/.makeflags`" ] ; then \
			echo "   [Warning] Make flags have changed since the last build" ; \
			echo "   [Warning] Previous build command: "`cat $(BUILD)/.makeflags`"" ; \
		fi ; \
	fi
	@echo "$(MAKEFLAGS)" >$(BUILD)/.makeflags

clean:
	rm -f "$(BUILD)/obj/async.o"
	rm -f "$(BUILD)/obj/atomic.o"
	rm -f "$(BUILD)/obj/benchMpr.o"
	rm -f "$(BUILD)/obj/buf.o"
	rm -f "$(BUILD)/obj/cache.o"
	rm -f "$(BUILD)/obj/cmd.o"
	rm -f "$(BUILD)/obj/cond.o"
	rm -f "$(BUILD)/obj/crypt.o"
	rm -f "$(BUILD)/obj/disk.o"
	rm -f "$(BUILD)/obj/dispatcher.o"
	rm -f "$(BUILD)/obj/encode.o"
	rm -f "$(BUILD)/obj/epoll.o"
	rm -f "$(BUILD)/obj/event.o"
	rm -f "$(BUILD)/obj/file.o"
	rm -f "$(BUILD)/obj/fs.o"
	rm -f "$(BUILD)/obj/hash.o"
	rm -f "$(BUILD)/obj/json.o"
	rm -f "$(BUILD)/obj/kqueue.o"
	rm -f "$(BUILD)/obj/list.o"
	rm -f "$(BUILD)/obj/lock.o"
	rm -f "$(BUILD)/obj/log.o"
	rm -f "$(BUILD)/obj/mbedtls.o"
	rm -f "$(BUILD)/obj/mem.o"
	rm -f "$(BUILD)/obj/mime.o"
	rm -f "$(BUILD)/obj/mixed.o"
	rm -f "$(BUILD)/obj/module.o"
	rm -f "$(BUILD)/obj/mpr-mbedtls.o"
	rm -f "$(BUILD)/obj/mpr-openssl.o"
	rm -f "$(BUILD)/obj/mpr.o"
	rm -f "$(BUILD)/obj/path.o"
	rm -f "$(BUILD)/obj/posix.o"
	rm -f "$(BUILD)/obj/printf.o"
	rm -f "$(BUILD)/obj/rom.o"
	rm -f "$(BUILD)/obj/runProgram.o"
	rm -f "$(BUILD)/obj/select.o"
	rm -f "$(BUILD)/obj/signal.o"
	rm -f "$(BUILD)/obj/socket.o"
	rm -f "$(BUILD)/obj/string.o"
	rm -f "$(BUILD)/obj/thread.o"
	rm -f "$(BUILD)/obj/time.o"
	rm -f "$(BUILD)/obj/vxworks.o"
	rm -f "$(BUILD)/obj/wait.o"
	rm -f "$(BUILD)/obj/wide.o"
	rm -f "$(BUILD)/obj/win.o"
	rm -f "$(BUILD)/obj/xml.o"
	rm -f "$(BUILD)/.install-certs-modified"
	rm -f "$(BUILD)/bin/libmbedtls.a"
	rm -f "$(BUILD)/bin/libmpr.so"
	rm -f "$(BUILD)/bin/libmpr-mbedtls.a"

clobber: clean
	rm -fr ./$(BUILD)

#
#   embedtls.h
#
DEPS_1 += src/mbedtls/embedtls.h

$(BUILD)/inc/embedtls.h: $(DEPS_1)
	@echo '      [Copy] $(BUILD)/inc/embedtls.h'
	mkdir -p "$(BUILD)/inc"
	cp src/mbedtls/embedtls.h $(BUILD)/inc/embedtls.h

#
#   mbedtls.h
#
DEPS_2 += src/mbedtls/mbedtls.h

$(BUILD)/inc/mbedtls.h: $(DEPS_2)
	@echo '      [Copy] $(BUILD)/inc/mbedtls.h'
	mkdir -p "$(BUILD)/inc"
	cp src/mbedtls/mbedtls.h $(BUILD)/inc/mbedtls.h

#
#   me.h
#

$(BUILD)/inc/me.h: $(DEPS_3)

#
#   osdep.h
#
DEPS_4 += src/osdep/osdep.h
DEPS_4 += $(BUILD)/inc/me.h

$(BUILD)/inc/osdep.h: $(DEPS_4)
	@echo '      [Copy] $(BUILD)/inc/osdep.h'
	mkdir -p "$(BUILD)/inc"
	cp src/osdep/osdep.h $(BUILD)/inc/osdep.h

#
#   mpr.h
#
DEPS_5 += src/mpr.h
DEPS_5 += $(BUILD)/inc/me.h
DEPS_5 += $(BUILD)/inc/osdep.h

$(BUILD)/inc/mpr.h: $(DEPS_5)
	@echo '      [Copy] $(BUILD)/inc/mpr.h'
	mkdir -p "$(BUILD)/inc"
	cp src/mpr.h $(BUILD)/inc/mpr.h

#
#   async.o
#
DEPS_6 += $(BUILD)/inc/mpr.h

$(BUILD)/obj/async.o: \
    src/async.c $(DEPS_6)
	@echo '   [Compile] $(BUILD)/obj/async.o'
	$(CC) -c -o $(BUILD)/obj/async.o $(LDFLAGS) $(CFLAGS) $(DFLAGS) -D_FILE_OFFSET_BITS=64 -DMBEDTLS_USER_CONFIG_FILE=\"embedtls.h\" $(IFLAGS) src/async.c

#
#   atomic.o
#
DEPS_7 += $(BUILD)/inc/mpr.h

$(BUILD)/obj/atomic.o: \
    src/atomic.c $(DEPS_7)
	@echo '   [Compile] $(BUILD)/obj/atomic.o'
	$(CC) -c -o $(BUILD)/obj/atomic.o $(LDFLAGS) $(CFLAGS) $(DFLAGS) -D_FILE_OFFSET_BITS=64 -DMBEDTLS_USER_CONFIG_FILE=\"embedtls.h\" $(IFLAGS) src/atomic.c

#
#   benchMpr.o
#
DEPS_8 += $(BUILD)/inc/mpr.h

$(BUILD)/obj/benchMpr.o: \
    test/benchMpr.c $(DEPS_8)
	@echo '   [Compile] $(BUILD)/obj/benchMpr.o'
	$(CC) -c -o $(BUILD)/obj/benchMpr.o $(LDFLAGS) $(CFLAGS) $(DFLAGS) -D_FILE_OFFSET_BITS=64 -DMBEDTLS_USER_CONFIG_FILE=\"embedtls.h\" $(IFLAGS) test/benchMpr.c

#
#   buf.o
#
DEPS_9 += $(BUILD)/inc/mpr.h

$(BUILD)/obj/buf.o: \
    src/buf.c $(DEPS_9)
	@echo '   [Compile] $(BUILD)/obj/buf.o'
	$(CC) -c -o $(BUILD)/obj/buf.o $(LDFLAGS) $(CFLAGS) $(DFLAGS) -D_FILE_OFFSET_BITS=64 -DMBEDTLS_USER_CONFIG_FILE=\"embedtls.h\" $(IFLAGS) src/buf.c

#
#   cache.o
#
DEPS_10 += $(BUILD)/inc/mpr.h

$(BUILD)/obj/cache.o: \
    src/cache.c $(DEPS_10)
	@echo '   [Compile] $(BUILD)/obj/cache.o'
	$(CC) -c -o $(BUILD)/obj/cache.o $(LDFLAGS) $(CFLAGS) $(DFLAGS) -D_FILE_OFFSET_BITS=64 -DMBEDTLS_USER_CONFIG_FILE=\"embedtls.h\" $(IFLAGS) src/cache.c

#
#   cmd.o
#
DEPS_11 += $(BUILD)/inc/mpr.h

$(BUILD)/obj/cmd.o: \
    src/cmd.c $(DEPS_11)
	@echo '   [Compile] $(BUILD)/obj/cmd.o'
	$(CC) -c -o $(BUILD)/obj/cmd.o $(LDFLAGS) $(CFLAGS) $(DFLAGS) -D_FILE_OFFSET_BITS=64 -DMBEDTLS_USER_CONFIG_FILE=\"embedtls.h\" $(IFLAGS) src/cmd.c

#
#   cond.o
#
DEPS_12 += $(BUILD)/inc/mpr.h

$(BUILD)/obj/cond.o: \
    src/cond.c $(DEPS_12)
	@echo '   [Compile] $(BUILD)/obj/cond.o'
	$(CC) -c -o $(BUILD)/obj/cond.o $(LDFLAGS) $(CFLAGS) $(DFLAGS) -D_FILE_OFFSET_BITS=64 -DMBEDTLS_USER_CONFIG_FILE=\"embedtls.h\" $(IFLAGS) src/cond.c

#
#   crypt.o
#
DEPS_13 += $(BUILD)/inc/mpr.h

$(BUILD)/obj/crypt.o: \
    src/crypt.c $(DEPS_13)
	@echo '   [Compile] $(BUILD)/obj/crypt.o'
	$(CC) -c -o $(BUILD)/obj/crypt.o $(LDFLAGS) $(CFLAGS) $(DFLAGS) -D_FILE_OFFSET_BITS=64 -DMBEDTLS_USER_CONFIG_FILE=\"embedtls.h\" $(IFLAGS) src/crypt.c

#
#   disk.o
#
DEPS_14 += $(BUILD)/inc/mpr.h

$(BUILD)/obj/disk.o: \
    src/disk.c $(DEPS_14)
	@echo '   [Compile] $(BUILD)/obj/disk.o'
	$(CC) -c -o $(BUILD)/obj/disk.o $(LDFLAGS) $(CFLAGS) $(DFLAGS) -D_FILE_OFFSET_BITS=64 -DMBEDTLS_USER_CONFIG_FILE=\"embedtls.h\" $(IFLAGS) src/disk.c

#
#   dispatcher.o
#
DEPS_15 += $(BUILD)/inc/mpr.h

$(BUILD)/obj/dispatcher.o: \
    src/dispatcher.c $(DEPS_15)
	@echo '   [Compile] $(BUILD)/obj/dispatcher.o'
	$(CC) -c -o $(BUILD)/obj/dispatcher.o $(LDFLAGS) $(CFLAGS) $(DFLAGS) -D_FILE_OFFSET_BITS=64 -DMBEDTLS_USER_CONFIG_FILE=\"embedtls.h\" $(IFLAGS) src/dispatcher.c

#
#   encode.o
#
DEPS_16 += $(BUILD)/inc/mpr.h

$(BUILD)/obj/encode.o: \
    src/encode.c $(DEPS_16)
	@echo '   [Compile] $(BUILD)/obj/encode.o'
	$(CC) -c -o $(BUILD)/obj/encode.o $(LDFLAGS) $(CFLAGS) $(DFLAGS) -D_FILE_OFFSET_BITS=64 -DMBEDTLS_USER_CONFIG_FILE=\"embedtls.h\" $(IFLAGS) src/encode.c

#
#   epoll.o
#
DEPS_17 += $(BUILD)/inc/mpr.h

$(BUILD)/obj/epoll.o: \
    src/epoll.c $(DEPS_17)
	@echo '   [Compile] $(BUILD)/obj/epoll.o'
	$(CC) -c -o $(BUILD)/obj/epoll.o $(LDFLAGS) $(CFLAGS) $(DFLAGS) -D_FILE_OFFSET_BITS=64 -DMBEDTLS_USER_CONFIG_FILE=\"embedtls.h\" $(IFLAGS) src/epoll.c

#
#   event.o
#
DEPS_18 += $(BUILD)/inc/mpr.h

$(BUILD)/obj/event.o: \
    src/event.c $(DEPS_18)
	@echo '   [Compile] $(BUILD)/obj/event.o'
	$(CC) -c -o $(BUILD)/obj/event.o $(LDFLAGS) $(CFLAGS) $(DFLAGS) -D_FILE_OFFSET_BITS=64 -DMBEDTLS_USER_CONFIG_FILE=\"embedtls.h\" $(IFLAGS) src/event.c

#
#   file.o
#
DEPS_19 += $(BUILD)/inc/mpr.h

$(BUILD)/obj/file.o: \
    src/file.c $(DEPS_19)
	@echo '   [Compile] $(BUILD)/obj/file.o'
	$(CC) -c -o $(BUILD)/obj/file.o $(LDFLAGS) $(CFLAGS) $(DFLAGS) -D_FILE_OFFSET_BITS=64 -DMBEDTLS_USER_CONFIG_FILE=\"embedtls.h\" $(IFLAGS) src/file.c

#
#   fs.o
#
DEPS_20 += $(BUILD)/inc/mpr.h

$(BUILD)/obj/fs.o: \
    src/fs.c $(DEPS_20)
	@echo '   [Compile] $(BUILD)/obj/fs.o'
	$(CC) -c -o $(BUILD)/obj/fs.o $(LDFLAGS) $(CFLAGS) $(DFLAGS) -D_FILE_OFFSET_BITS=64 -DMBEDTLS_USER_CONFIG_FILE=\"embedtls.h\" $(IFLAGS) src/fs.c

#
#   hash.o
#
DEPS_21 += $(BUILD)/inc/mpr.h

$(BUILD)/obj/hash.o: \
    src/hash.c $(DEPS_21)
	@echo '   [Compile] $(BUILD)/obj/hash.o'
	$(CC) -c -o $(BUILD)/obj/hash.o $(LDFLAGS) $(CFLAGS) $(DFLAGS) -D_FILE_OFFSET_BITS=64 -DMBEDTLS_USER_CONFIG_FILE=\"embedtls.h\" $(IFLAGS) src/hash.c

#
#   json.o
#
DEPS_22 += $(BUILD)/inc/mpr.h

$(BUILD)/obj/json.o: \
    src/json.c $(DEPS_22)
	@echo '   [Compile] $(BUILD)/obj/json.o'
	$(CC) -c -o $(BUILD)/obj/json.o $(LDFLAGS) $(CFLAGS) $(DFLAGS) -D_FILE_OFFSET_BITS=64 -DMBEDTLS_USER_CONFIG_FILE=\"embedtls.h\" $(IFLAGS) src/json.c

#
#   kqueue.o
#
DEPS_23 += $(BUILD)/inc/mpr.h

$(BUILD)/obj/kqueue.o: \
    src/kqueue.c $(DEPS_23)
	@echo '   [Compile] $(BUILD)/obj/kqueue.o'
	$(CC) -c -o $(BUILD)/obj/kqueue.o $(LDFLAGS) $(CFLAGS) $(DFLAGS) -D_FILE_OFFSET_BITS=64 -DMBEDTLS_USER_CONFIG_FILE=\"embedtls.h\" $(IFLAGS) src/kqueue.c

#
#   list.o
#
DEPS_24 += $(BUILD)/inc/mpr.h

$(BUILD)/obj/list.o: \
    src/list.c $(DEPS_24)
	@echo '   [Compile] $(BUILD)/obj/list.o'
	$(CC) -c -o $(BUILD)/obj/list.o $(LDFLAGS) $(CFLAGS) $(DFLAGS) -D_FILE_OFFSET_BITS=64 -DMBEDTLS_USER_CONFIG_FILE=\"embedtls.h\" $(IFLAGS) src/list.c

#
#   lock.o
#
DEPS_25 += $(BUILD)/inc/mpr.h

$(BUILD)/obj/lock.o: \
    src/lock.c $(DEPS_25)
	@echo '   [Compile] $(BUILD)/obj/lock.o'
	$(CC) -c -o $(BUILD)/obj/lock.o $(LDFLAGS) $(CFLAGS) $(DFLAGS) -D_FILE_OFFSET_BITS=64 -DMBEDTLS_USER_CONFIG_FILE=\"embedtls.h\" $(IFLAGS) src/lock.c

#
#   log.o
#
DEPS_26 += $(BUILD)/inc/mpr.h

$(BUILD)/obj/log.o: \
    src/log.c $(DEPS_26)
	@echo '   [Compile] $(BUILD)/obj/log.o'
	$(CC) -c -o $(BUILD)/obj/log.o $(LDFLAGS) $(CFLAGS) $(DFLAGS) -D_FILE_OFFSET_BITS=64 -DMBEDTLS_USER_CONFIG_FILE=\"embedtls.h\" $(IFLAGS) src/log.c

#
#   mbedtls.h
#

src/mbedtls/mbedtls.h: $(DEPS_27)

#
#   mbedtls.o
#
DEPS_28 += src/mbedtls/mbedtls.h

$(BUILD)/obj/mbedtls.o: \
    src/mbedtls/mbedtls.c $(DEPS_28)
	@echo '   [Compile] $(BUILD)/obj/mbedtls.o'
	$(CC) -c -o $(BUILD)/obj/mbedtls.o $(LDFLAGS) $(CFLAGS) $(DFLAGS) -DMBEDTLS_USER_CONFIG_FILE=\"embedtls.h\" $(IFLAGS) src/mbedtls/mbedtls.c

#
#   mem.o
#
DEPS_29 += $(BUILD)/inc/mpr.h

$(BUILD)/obj/mem.o: \
    src/mem.c $(DEPS_29)
	@echo '   [Compile] $(BUILD)/obj/mem.o'
	$(CC) -c -o $(BUILD)/obj/mem.o $(LDFLAGS) $(CFLAGS) $(DFLAGS) -D_FILE_OFFSET_BITS=64 -DMBEDTLS_USER_CONFIG_FILE=\"embedtls.h\" $(IFLAGS) src/mem.c

#
#   mime.o
#
DEPS_30 += $(BUILD)/inc/mpr.h

$(BUILD)/obj/mime.o: \
    src/mime.c $(DEPS_30)
	@echo '   [Compile] $(BUILD)/obj/mime.o'
	$(CC) -c -o $(BUILD)/obj/mime.o $(LDFLAGS) $(CFLAGS) $(DFLAGS) -D_FILE_OFFSET_BITS=64 -DMBEDTLS_USER_CONFIG_FILE=\"embedtls.h\" $(IFLAGS) src/mime.c

#
#   mixed.o
#
DEPS_31 += $(BUILD)/inc/mpr.h

$(BUILD)/obj/mixed.o: \
    src/mixed.c $(DEPS_31)
	@echo '   [Compile] $(BUILD)/obj/mixed.o'
	$(CC) -c -o $(BUILD)/obj/mixed.o $(LDFLAGS) $(CFLAGS) $(DFLAGS) -D_FILE_OFFSET_BITS=64 -DMBEDTLS_USER_CONFIG_FILE=\"embedtls.h\" $(IFLAGS) src/mixed.c

#
#   module.o
#
DEPS_32 += $(BUILD)/inc/mpr.h

$(BUILD)/obj/module.o: \
    src/module.c $(DEPS_32)
	@echo '   [Compile] $(BUILD)/obj/module.o'
	$(CC) -c -o $(BUILD)/obj/module.o $(LDFLAGS) $(CFLAGS) $(DFLAGS) -D_FILE_OFFSET_BITS=64 -DMBEDTLS_USER_CONFIG_FILE=\"embedtls.h\" $(IFLAGS) src/module.c

#
#   mpr-mbedtls.o
#
DEPS_33 += $(BUILD)/inc/mpr.h

$(BUILD)/obj/mpr-mbedtls.o: \
    src/mpr-mbedtls/mpr-mbedtls.c $(DEPS_33)
	@echo '   [Compile] $(BUILD)/obj/mpr-mbedtls.o'
	$(CC) -c -o $(BUILD)/obj/mpr-mbedtls.o $(LDFLAGS) $(CFLAGS) $(DFLAGS) -D_FILE_OFFSET_BITS=64 -DMBEDTLS_USER_CONFIG_FILE=\"embedtls.h\" $(IFLAGS) src/mpr-mbedtls/mpr-mbedtls.c

#
#   mpr-openssl.o
#
DEPS_34 += $(BUILD)/inc/mpr.h

$(BUILD)/obj/mpr-openssl.o: \
    src/mpr-openssl/mpr-openssl.c $(DEPS_34)
	@echo '   [Compile] $(BUILD)/obj/mpr-openssl.o'
	$(CC) -c -o $(BUILD)/obj/mpr-openssl.o $(LDFLAGS) $(CFLAGS) $(DFLAGS) $(IFLAGS) src/mpr-openssl/mpr-openssl.c

#
#   mpr.o
#
DEPS_35 += $(BUILD)/inc/mpr.h

$(BUILD)/obj/mpr.o: \
    src/mpr.c $(DEPS_35)
	@echo '   [Compile] $(BUILD)/obj/mpr.o'
	$(CC) -c -o $(BUILD)/obj/mpr.o $(LDFLAGS) $(CFLAGS) $(DFLAGS) -D_FILE_OFFSET_BITS=64 -DMBEDTLS_USER_CONFIG_FILE=\"embedtls.h\" $(IFLAGS) src/mpr.c

#
#   path.o
#
DEPS_36 += $(BUILD)/inc/mpr.h

$(BUILD)/obj/path.o: \
    src/path.c $(DEPS_36)
	@echo '   [Compile] $(BUILD)/obj/path.o'
	$(CC) -c -o $(BUILD)/obj/path.o $(LDFLAGS) $(CFLAGS) $(DFLAGS) -D_FILE_OFFSET_BITS=64 -DMBEDTLS_USER_CONFIG_FILE=\"embedtls.h\" $(IFLAGS) src/path.c

#
#   posix.o
#
DEPS_37 += $(BUILD)/inc/mpr.h

$(BUILD)/obj/posix.o: \
    src/posix.c $(DEPS_37)
	@echo '   [Compile] $(BUILD)/obj/posix.o'
	$(CC) -c -o $(BUILD)/obj/posix.o $(LDFLAGS) $(CFLAGS) $(DFLAGS) -D_FILE_OFFSET_BITS=64 -DMBEDTLS_USER_CONFIG_FILE=\"embedtls.h\" $(IFLAGS) src/posix.c

#
#   printf.o
#
DEPS_38 += $(BUILD)/inc/mpr.h

$(BUILD)/obj/printf.o: \
    src/printf.c $(DEPS_38)
	@echo '   [Compile] $(BUILD)/obj/printf.o'
	$(CC) -c -o $(BUILD)/obj/printf.o $(LDFLAGS) $(CFLAGS) $(DFLAGS) -D_FILE_OFFSET_BITS=64 -DMBEDTLS_USER_CONFIG_FILE=\"embedtls.h\" $(IFLAGS) src/printf.c

#
#   rom.o
#
DEPS_39 += $(BUILD)/inc/mpr.h

$(BUILD)/obj/rom.o: \
    src/rom.c $(DEPS_39)
	@echo '   [Compile] $(BUILD)/obj/rom.o'
	$(CC) -c -o $(BUILD)/obj/rom.o $(LDFLAGS) $(CFLAGS) $(DFLAGS) -D_FILE_OFFSET_BITS=64 -DMBEDTLS_USER_CONFIG_FILE=\"embedtls.h\" $(IFLAGS) src/rom.c

#
#   runProgram.o
#
DEPS_40 += $(BUILD)/inc/me.h

$(BUILD)/obj/runProgram.o: \
    test/runProgram.c $(DEPS_40)
	@echo '   [Compile] $(BUILD)/obj/runProgram.o'
	$(CC) -c -o $(BUILD)/obj/runProgram.o $(LDFLAGS) $(CFLAGS) $(DFLAGS) $(IFLAGS) test/runProgram.c

#
#   select.o
#
DEPS_41 += $(BUILD)/inc/mpr.h

$(BUILD)/obj/select.o: \
    src/select.c $(DEPS_41)
	@echo '   [Compile] $(BUILD)/obj/select.o'
	$(CC) -c -o $(BUILD)/obj/select.o $(LDFLAGS) $(CFLAGS) $(DFLAGS) -D_FILE_OFFSET_BITS=64 -DMBEDTLS_USER_CONFIG_FILE=\"embedtls.h\" $(IFLAGS) src/select.c

#
#   signal.o
#
DEPS_42 += $(BUILD)/inc/mpr.h

$(BUILD)/obj/signal.o: \
    src/signal.c $(DEPS_42)
	@echo '   [Compile] $(BUILD)/obj/signal.o'
	$(CC) -c -o $(BUILD)/obj/signal.o $(LDFLAGS) $(CFLAGS) $(DFLAGS) -D_FILE_OFFSET_BITS=64 -DMBEDTLS_USER_CONFIG_FILE=\"embedtls.h\" $(IFLAGS) src/signal.c

#
#   socket.o
#
DEPS_43 += $(BUILD)/inc/mpr.h

$(BUILD)/obj/socket.o: \
    src/socket.c $(DEPS_43)
	@echo '   [Compile] $(BUILD)/obj/socket.o'
	$(CC) -c -o $(BUILD)/obj/socket.o $(LDFLAGS) $(CFLAGS) $(DFLAGS) -D_FILE_OFFSET_BITS=64 -DMBEDTLS_USER_CONFIG_FILE=\"embedtls.h\" $(IFLAGS) src/socket.c

#
#   string.o
#
DEPS_44 += $(BUILD)/inc/mpr.h

$(BUILD)/obj/string.o: \
    src/string.c $(DEPS_44)
	@echo '   [Compile] $(BUILD)/obj/string.o'
	$(CC) -c -o $(BUILD)/obj/string.o $(LDFLAGS) $(CFLAGS) $(DFLAGS) -D_FILE_OFFSET_BITS=64 -DMBEDTLS_USER_CONFIG_FILE=\"embedtls.h\" $(IFLAGS) src/string.c

#
#   thread.o
#
DEPS_45 += $(BUILD)/inc/mpr.h

$(BUILD)/obj/thread.o: \
    src/thread.c $(DEPS_45)
	@echo '   [Compile] $(BUILD)/obj/thread.o'
	$(CC) -c -o $(BUILD)/obj/thread.o $(LDFLAGS) $(CFLAGS) $(DFLAGS) -D_FILE_OFFSET_BITS=64 -DMBEDTLS_USER_CONFIG_FILE=\"embedtls.h\" $(IFLAGS) src/thread.c

#
#   time.o
#
DEPS_46 += $(BUILD)/inc/mpr.h

$(BUILD)/obj/time.o: \
    src/time.c $(DEPS_46)
	@echo '   [Compile] $(BUILD)/obj/time.o'
	$(CC) -c -o $(BUILD)/obj/time.o $(LDFLAGS) $(CFLAGS) $(DFLAGS) -D_FILE_OFFSET_BITS=64 -DMBEDTLS_USER_CONFIG_FILE=\"embedtls.h\" $(IFLAGS) src/time.c

#
#   vxworks.o
#
DEPS_47 += $(BUILD)/inc/mpr.h

$(BUILD)/obj/vxworks.o: \
    src/vxworks.c $(DEPS_47)
	@echo '   [Compile] $(BUILD)/obj/vxworks.o'
	$(CC) -c -o $(BUILD)/obj/vxworks.o $(LDFLAGS) $(CFLAGS) $(DFLAGS) -D_FILE_OFFSET_BITS=64 -DMBEDTLS_USER_CONFIG_FILE=\"embedtls.h\" $(IFLAGS) src/vxworks.c

#
#   wait.o
#
DEPS_48 += $(BUILD)/inc/mpr.h

$(BUILD)/obj/wait.o: \
    src/wait.c $(DEPS_48)
	@echo '   [Compile] $(BUILD)/obj/wait.o'
	$(CC) -c -o $(BUILD)/obj/wait.o $(LDFLAGS) $(CFLAGS) $(DFLAGS) -D_FILE_OFFSET_BITS=64 -DMBEDTLS_USER_CONFIG_FILE=\"embedtls.h\" $(IFLAGS) src/wait.c

#
#   wide.o
#
DEPS_49 += $(BUILD)/inc/mpr.h

$(BUILD)/obj/wide.o: \
    src/wide.c $(DEPS_49)
	@echo '   [Compile] $(BUILD)/obj/wide.o'
	$(CC) -c -o $(BUILD)/obj/wide.o $(LDFLAGS) $(CFLAGS) $(DFLAGS) -D_FILE_OFFSET_BITS=64 -DMBEDTLS_USER_CONFIG_FILE=\"embedtls.h\" $(IFLAGS) src/wide.c

#
#   win.o
#
DEPS_50 += $(BUILD)/inc/mpr.h

$(BUILD)/obj/win.o: \
    src/win.c $(DEPS_50)
	@echo '   [Compile] $(BUILD)/obj/win.o'
	$(CC) -c -o $(BUILD)/obj/win.o $(LDFLAGS) $(CFLAGS) $(DFLAGS) -D_FILE_OFFSET_BITS=64 -DMBEDTLS_USER_CONFIG_FILE=\"embedtls.h\" $(IFLAGS) src/win.c

#
#   xml.o
#
DEPS_51 += $(BUILD)/inc/mpr.h

$(BUILD)/obj/xml.o: \
    src/xml.c $(DEPS_51)
	@echo '   [Compile] $(BUILD)/obj/xml.o'
	$(CC) -c -o $(BUILD)/obj/xml.o $(LDFLAGS) $(CFLAGS) $(DFLAGS) -D_FILE_OFFSET_BITS=64 -DMBEDTLS_USER_CONFIG_FILE=\"embedtls.h\" $(IFLAGS) src/xml.c

#
#   install-certs
#
DEPS_52 += src/certs/samples/ca.crt
DEPS_52 += src/certs/samples/ca.key
DEPS_52 += src/certs/samples/ec.crt
DEPS_52 += src/certs/samples/ec.key
DEPS_52 += src/certs/samples/roots.crt
DEPS_52 += src/certs/samples/self.crt
DEPS_52 += src/certs/samples/self.key
DEPS_52 += src/certs/samples/test.crt
DEPS_52 += src/certs/samples/test.key

$(BUILD)/.install-certs-modified: $(DEPS_52)
	@echo '      [Copy] $(BUILD)/bin'
	mkdir -p "$(BUILD)/bin"
	cp src/certs/samples/ca.crt $(BUILD)/bin/ca.crt
	cp src/certs/samples/ca.key $(BUILD)/bin/ca.key
	cp src/certs/samples/ec.crt $(BUILD)/bin/ec.crt
	cp src/certs/samples/ec.key $(BUILD)/bin/ec.key
	cp src/certs/samples/roots.crt $(BUILD)/bin/roots.crt
	cp src/certs/samples/self.crt $(BUILD)/bin/self.crt
	cp src/certs/samples/self.key $(BUILD)/bin/self.key
	cp src/certs/samples/test.crt $(BUILD)/bin/test.crt
	cp src/certs/samples/test.key $(BUILD)/bin/test.key
	touch "$(BUILD)/.install-certs-modified"

ifeq ($(ME_COM_MBEDTLS),1)
#
#   libmbedtls
#
DEPS_53 += $(BUILD)/inc/osdep.h
DEPS_53 += $(BUILD)/inc/embedtls.h
DEPS_53 += $(BUILD)/inc/mbedtls.h
DEPS_53 += $(BUILD)/obj/mbedtls.o

$(BUILD)/bin/libmbedtls.a: $(DEPS_53)
	@echo '      [Link] $(BUILD)/bin/libmbedtls.a'
	ar -cr $(BUILD)/bin/libmbedtls.a "$(BUILD)/obj/mbedtls.o"
endif

ifeq ($(ME_COM_MBEDTLS),1)
#
#   libmpr-mbedtls
#
DEPS_54 += $(BUILD)/bin/libmbedtls.a
DEPS_54 += $(BUILD)/obj/mpr-mbedtls.o

$(BUILD)/bin/libmpr-mbedtls.a: $(DEPS_54)
	@echo '      [Link] $(BUILD)/bin/libmpr-mbedtls.a'
	ar -cr $(BUILD)/bin/libmpr-mbedtls.a "$(BUILD)/obj/mpr-mbedtls.o"
endif

ifeq ($(ME_COM_OPENSSL),1)
#
#   libmpr-openssl
#
DEPS_55 += $(BUILD)/obj/mpr-openssl.o

$(BUILD)/bin/libmpr-openssl.a: $(DEPS_55)
	@echo '      [Link] $(BUILD)/bin/libmpr-openssl.a'
	ar -cr $(BUILD)/bin/libmpr-openssl.a "$(BUILD)/obj/mpr-openssl.o"
endif

#
#   libmpr
#
DEPS_56 += $(BUILD)/inc/osdep.h
ifeq ($(ME_COM_MBEDTLS),1)
    DEPS_56 += $(BUILD)/bin/libmpr-mbedtls.a
endif
ifeq ($(ME_COM_MBEDTLS),1)
    DEPS_56 += $(BUILD)/bin/libmbedtls.a
endif
ifeq ($(ME_COM_OPENSSL),1)
    DEPS_56 += $(BUILD)/bin/libmpr-openssl.a
endif
DEPS_56 += $(BUILD)/inc/mpr.h
DEPS_56 += $(BUILD)/obj/async.o
DEPS_56 += $(BUILD)/obj/atomic.o
DEPS_56 += $(BUILD)/obj/buf.o
DEPS_56 += $(BUILD)/obj/cache.o
DEPS_56 += $(BUILD)/obj/cmd.o
DEPS_56 += $(BUILD)/obj/cond.o
DEPS_56 += $(BUILD)/obj/crypt.o
DEPS_56 += $(BUILD)/obj/disk.o
DEPS_56 += $(BUILD)/obj/dispatcher.o
DEPS_56 += $(BUILD)/obj/encode.o
DEPS_56 += $(BUILD)/obj/epoll.o
DEPS_56 += $(BUILD)/obj/event.o
DEPS_56 += $(BUILD)/obj/file.o
DEPS_56 += $(BUILD)/obj/fs.o
DEPS_56 += $(BUILD)/obj/hash.o
DEPS_56 += $(BUILD)/obj/json.o
DEPS_56 += $(BUILD)/obj/kqueue.o
DEPS_56 += $(BUILD)/obj/list.o
DEPS_56 += $(BUILD)/obj/lock.o
DEPS_56 += $(BUILD)/obj/log.o
DEPS_56 += $(BUILD)/obj/mem.o
DEPS_56 += $(BUILD)/obj/mime.o
DEPS_56 += $(BUILD)/obj/mixed.o
DEPS_56 += $(BUILD)/obj/module.o
DEPS_56 += $(BUILD)/obj/mpr.o
DEPS_56 += $(BUILD)/obj/path.o
DEPS_56 += $(BUILD)/obj/posix.o
DEPS_56 += $(BUILD)/obj/printf.o
DEPS_56 += $(BUILD)/obj/rom.o
DEPS_56 += $(BUILD)/obj/select.o
DEPS_56 += $(BUILD)/obj/signal.o
DEPS_56 += $(BUILD)/obj/socket.o
DEPS_56 += $(BUILD)/obj/string.o
DEPS_56 += $(BUILD)/obj/thread.o
DEPS_56 += $(BUILD)/obj/time.o
DEPS_56 += $(BUILD)/obj/vxworks.o
DEPS_56 += $(BUILD)/obj/wait.o
DEPS_56 += $(BUILD)/obj/wide.o
DEPS_56 += $(BUILD)/obj/win.o
DEPS_56 += $(BUILD)/obj/xml.o

ifeq ($(ME_COM_MBEDTLS),1)
    LIBS_56 += -lmbedtls
endif
ifeq ($(ME_COM_MBEDTLS),1)
    LIBS_56 += -lmpr-mbedtls
endif
ifeq ($(ME_COM_MBEDTLS),1)
    LIBS_56 += -lmbedtls
endif
ifeq ($(ME_COM_OPENSSL),1)
    LIBS_56 += -lmpr-openssl
endif
ifeq ($(ME_COM_MBEDTLS),1)
    LIBS_56 += -lmpr-mbedtls
endif

$(BUILD)/bin/libmpr.so: $(DEPS_56)
	@echo '      [Link] $(BUILD)/bin/libmpr.so'
	$(CC) -shared -o $(BUILD)/bin/libmpr.so $(LDFLAGS) $(LIBPATHS) "$(BUILD)/obj/async.o" "$(BUILD)/obj/atomic.o" "$(BUILD)/obj/buf.o" "$(BUILD)/obj/cache.o" "$(BUILD)/obj/cmd.o" "$(BUILD)/obj/cond.o" "$(BUILD)/obj/crypt.o" "$(BUILD)/obj/disk.o" "$(BUILD)/obj/dispatcher.o" "$(BUILD)/obj/encode.o" "$(BUILD)/obj/epoll.o" "$(BUILD)/obj/event.o" "$(BUILD)/obj/file.o" "$(BUILD)/obj/fs.o" "$(BUILD)/obj/hash.o" "$(BUILD)/obj/json.o" "$(BUILD)/obj/kqueue.o" "$(BUILD)/obj/list.o" "$(BUILD)/obj/lock.o" "$(BUILD)/obj/log.o" "$(BUILD)/obj/mem.o" "$(BUILD)/obj/mime.o" "$(BUILD)/obj/mixed.o" "$(BUILD)/obj/module.o" "$(BUILD)/obj/mpr.o" "$(BUILD)/obj/path.o" "$(BUILD)/obj/posix.o" "$(BUILD)/obj/printf.o" "$(BUILD)/obj/rom.o" "$(BUILD)/obj/select.o" "$(BUILD)/obj/signal.o" "$(BUILD)/obj/socket.o" "$(BUILD)/obj/string.o" "$(BUILD)/obj/thread.o" "$(BUILD)/obj/time.o" "$(BUILD)/obj/vxworks.o" "$(BUILD)/obj/wait.o" "$(BUILD)/obj/wide.o" "$(BUILD)/obj/win.o" "$(BUILD)/obj/xml.o" $(LIBPATHS_56) $(LIBS_56) $(LIBS_56) $(LIBS) 

#
#   installPrep
#

installPrep: $(DEPS_57)
	if [ "`id -u`" != 0 ] ; \
	then echo "Must run as root. Rerun with "sudo"" ; \
	exit 255 ; \
	fi

#
#   stop
#

stop: $(DEPS_58)

#
#   installBinary
#

installBinary: $(DEPS_59)

#
#   start
#

start: $(DEPS_60)

#
#   install
#
DEPS_61 += installPrep
DEPS_61 += stop
DEPS_61 += installBinary
DEPS_61 += start

install: $(DEPS_61)

#
#   uninstall
#
DEPS_62 += stop

uninstall: $(DEPS_62)

#
#   version
#

version: $(DEPS_63)
	echo $(VERSION)

